package com.xx.config;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.catalina.Manager;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

@Component
public class LoginInterceptor implements HandlerInterceptor {

	/**
	 * 登录拦截处理
	 */
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		Manager manager = (Manager)request.getSession().getAttribute("manager");
		if (manager == null) {
			String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + "/dashboard";
			response.sendRedirect(basePath);
			return false;
		}
		return true;
	}
}